package icu.cocoon.work.controller;


import icu.cocoon.dao.base.Resp;
import icu.cocoon.work.pojo.param.StudyInfoParam;
import icu.cocoon.work.service.WechatArticleService;
import io.swagger.annotations.Api;
import javax.annotation.Resource;
import javax.validation.Valid;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "学习")
@RestController
@RequestMapping("/studyInfo")
public class StudyInfoController {

  @Resource
  private WechatArticleService wechatArticleService;

  @PostMapping("saveStudyInfo")
  public Resp<?> saveStudyInfo(@RequestBody @Valid StudyInfoParam param) {
    do {
      param.setLookTime(param.getLookTime() + 5);
      wechatArticleService.save(param);
    } while (param.getLookTime() < param.getSectionTime());
    System.out.println("课程学习脚本结束");
    return Resp.success();
  }

}
